package com.guchenbo.example.ds.order;

/**
 * Created by CreGu on 2016/5/25.
 */
public class ArrayAbstract {
    protected long[] arr;
    protected int elements;

    public ArrayAbstract(int size) {
        arr = new long[size];
        elements = 0;
        setUp(size);
    }

    public void setUp(int size) {
        for (int i = 0; i < size; i++) {
            insert((long) (Math.random() * size * 16));
        }
    }

    public void insert(long element) {
        arr[elements++] = element;
    }

    public void display() {
        StringBuffer stringBuffer = new StringBuffer();

        for (int i = 0; i < elements; i++) {
            stringBuffer.append(arr[i]);
            if (i < elements - 1) {
                stringBuffer.append(", ");
            }
        }
        System.out.println(stringBuffer.toString());
    }
}
